<?php

defined('_JEXEC') or die('Restricted access');
use Joomla\Registry\Registry;
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/tables');

class ConsoleModelConversion extends JModelList
{
    public function getFunnels()
    {
        $user = JFactory::getUser();
        $db = $this->getDbo();
        $query = $db->getQuery(true);
        $query->select('a.id, a.name')
            ->from('pp_funnel_cfg a')
            ->where('a.app_id in (select b.id from pp_app b where b.account_id='
                . $user->id . ')');
        $session = JFactory::getSession();
        $appId = $session->get('appId', -1);
        if ($appId > -1) {
        	$query->where('a.app_id=' . $appId);
        }
        $db->setQuery($query);
        $items = $this->_getList($query);
        if (count($items) > 0) {
	        foreach ($items as $key => $item) {
	            $itemArray[$item->id] = $item;
	        }
        }
        else {
        	$itemArray = array();
        }
        return $itemArray;
    }
}
